/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmPageControlStyle.h"

#include "prs_FrmButtonStyle.h"

using namespace prs;

// TRuleFrmPageControlStyle /////////////////////////////////////////////////////

//
TRuleFrmPageControlStyle::TRuleFrmPageControlStyle(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmStyleState &RStyleState
) 
:vParentNode(VParentNode)
,rStyleState(RStyleState)
{
  snt::TReturn Return;
  snt::TFVoid F;
  snt::text::TSequence T(Context);
  snt::text::TNumber N(Context);
  snt::text::TKeyword K(Context);
  prs::TFuncNewNodeIntoAttrOldChildren FNewNode;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("pageControl") & FNewNode.New(VParentNode,TNodeFrmPageControlStyle()) & T.New("(") & A.New()
  ;
  
  A.Name(GetClassName() + "[A]")
  | T.New("pageControl")  & F.New(this,&TRuleFrmPageControlStyle::FPageControl)  & rStyleState.New() & A.New()
  | T.New("client")		  & F.New(this,&TRuleFrmPageControlStyle::FClient)		 & rStyleState.New() & A.New()
  | T.New("buttons")	  & F.New(this,&TRuleFrmPageControlStyle::FButtons)		 & rStyleState.New() & A.New()
  
  | T.New(")") & Return.New()
  ;

}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

// TRuleFrmPageStyle /////////////////////////////////////////////////////

//
TRuleFrmPageStyle::TRuleFrmPageStyle(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmStyleState &RStyleState
) 
:vParentNode(VParentNode)
,rStyleState(RStyleState)
{
  snt::TReturn Return;
  snt::TFVoid F;
  snt::text::TSequence T(Context);
  snt::text::TNumber   N(Context);
  snt::text::TKeyword  K(Context);
  snt::text::TIdent    I(Context);
  prs::TFuncNewNodeIntoAttrOldChildren   FNewNode;

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("page") & FNewNode.New(VParentNode,TNodeFrmPageStyle()) & T.New("(") & A.New()
  ;
  
  A.Name(GetClassName() + "[A]")
  //| T.New("pageButton") & T.New("=") & I.NewClosure(this,&TRuleFrmPageStyle::FPageButton) & A.New()
  | T.New("page") & F.New(this,&TRuleFrmPageStyle::FPage) & rStyleState.New() & A.New()
  
  | T.New(")") & Return.New()
  ;
}


/*/
bool TRuleFrmPageStyle::FPageButton(snt::text::TIdent::TFuncClosureDoEntryParams &Params)
{
	TNodeFrmPageStyle* Page = dynamic_cast<TNodeFrmPageStyle*>(vParentNode.Pointer());
	
	TNodeUnit *Unit = dynamic_cast<TNodeUnit*>(
				TNodeSearch(Page)
				.SearchNearParentByType(TNodeFrm::nodeType_Unit)
				.GetFirst() );
	
	TNode* style = Unit->SearchStyleById( Params.Ident.GetValue().String() );
	
	if( !style ){
		Params.OutError << "Style " << Params.Ident.GetValue().String() << " not found.";
		return false;
	}

	TNodeFrmButtonStyle* button = dynamic_cast<TNodeFrmButtonStyle*>(
				TNodeSearch(style)
				.SearchChildren()
				.SearchByType(TNodeFrm::nodeType_Button)
				.GetFirst() );
	
	if( !button ){
		Params.OutError << "Button style in " << Params.Ident.GetValue().String() << " not found.";
		return false;
	}

	Page->Style.Value.Button.SetFromParent( &button->Style.Value );

	return true;
}
*/